package com.javaclimb.drug.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.javaclimb.drug.common.ResultMapUtil;
import com.javaclimb.drug.entity.Classesinfo;
import com.javaclimb.drug.service.IClassesinfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.Date;
import java.util.List;

/**
 * 图像类别的controller
 */
@Controller
@RequestMapping(value = "/classes")
public class ClassesinfoController {

    @Autowired
    private IClassesinfoService iClassesinfoService;

    /**
     * 图库页面
     */
    @RequestMapping
    public String classesInfo(){
        return "/classesInfo";
    }

    /**
     * 分页查询供应商列表
     */
    @RequestMapping(value = "/classesQueryPage")
    @ResponseBody
    public Object classesinfoQueryPage(String param, @RequestParam(defaultValue = "1")int pageNum,@RequestParam(defaultValue = "10")int pageSize){
        try{
            IPage<Classesinfo> iPage = iClassesinfoService.selectClassesinfoPage(pageNum,pageSize,param);
            return ResultMapUtil.getHashMapMysqlPage(iPage);
        } catch (Exception e){
            return ResultMapUtil.getHashMapException(e);
        }
    }

    /**
     * 转向供应商新增页面
     */
    @RequestMapping(value = "/classesInfoPage")
    public String classesinfoPage(){
        return "/classesInfoPage";
    }

    /**
     * 添加一个图片数据
     */
    @RequestMapping(value = "/classesInfoAdd")
    @ResponseBody
    public Object classesinfoAdd(Classesinfo classesinfo){
        try{
            classesinfo.setUpdatetime(new Date());
            int i = iClassesinfoService.addClassesinfo(classesinfo);
            return ResultMapUtil.getHashMapSave(i);
        } catch (Exception e){
            return ResultMapUtil.getHashMapException(e);
        }
    }

    /**
     * 转向供应商编辑页面
     */
    @RequestMapping(value = "/classesInfoQueryById")
    public String classesInfoQueryById(@RequestParam(name = "id",required = true)Integer id, Model model){
        Classesinfo classesinfo = iClassesinfoService.queryClassesinfoById(id);
        model.addAttribute("obj",classesinfo);
        return "/classesInfoPage";
    }

    /**
     * 修改一个供应商
     */
    @RequestMapping(value = "/classesInfoEdit")
    @ResponseBody
    public Object classesInfoEdit(Classesinfo classesinfo){
        try{
            classesinfo.setUpdatetime(new Date());
            int i = iClassesinfoService.editClassesinfo(classesinfo);
            return ResultMapUtil.getHashMapSave(i);
        } catch (Exception e){
            return ResultMapUtil.getHashMapException(e);
        }
    }

    /**
     * 删除一个供应商
     */
    @RequestMapping(value = "/classesInfoDelById")
    @ResponseBody
    public Object classesInfoDelById(Integer id){
        try{
            int i = iClassesinfoService.delClassesinfoById(id);
            return ResultMapUtil.getHashMapDel(i);
        } catch (Exception e){
            return ResultMapUtil.getHashMapException(e);
        }
    }

    /**
     * 获取所有供应商
     */
    @RequestMapping(value = "/classesInfoList")
    @ResponseBody
    public Object classesInfoList(){
        List<Classesinfo> classesinfoList = iClassesinfoService.queryClassesinfoList();
        return ResultMapUtil.getHashMapList(classesinfoList);
    }
}





















